package com.youi.web;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.youi.exception.BusinessException;
import com.youi.manage.HttpRequestManage;
import com.youi.common.DelStatus;
import com.youi.service.MerchantidisqcService;
import com.youi.entity.Merchantidisqc;
import com.youi.common.Common;
import com.youi.util.CommonInfoUtil;
import com.youi.util.DateUtil;
import com.youi.util.JsonUtil;
import com.youi.util.ObjectUtil;
import com.youi.util.Page;

/**
* 互联网药品信息服务资格证书控制层
* @author Administrator
*/
@Controller
public class MerchantidisqcController  extends HttpRequestManage{

		@Autowired
		private MerchantidisqcService merchantidisqcService;

		/**
		 * I-75
		 * 添加或编辑互联网药品信息服务资格证书
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/addOrEditMerchantidisqc")
		public String addOrEditMerchantidisqc(ModelMap modelMap,HttpServletRequest request)throws BusinessException,ParseException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);
			Merchantidisqc merchantidisqc=merchantidisqcService.getByParam(prams);
			if (merchantidisqc==null) {
				merchantidisqc=new Merchantidisqc();
				merchantidisqc.setDelStatus(DelStatus.NODEL);
				merchantidisqc.setGmtCreated(new Date());
				merchantidisqc.setMerchantId(id);
			}
			String certNo=optString("certNo",request);
			if (certNo!=null){
				merchantidisqc.setCertNo(certNo);
			}
			String internetLeader=optString("internetLeader",request);
			if (internetLeader!=null){
				merchantidisqc.setInternetLeader(internetLeader);
			}
			String websiteDomain=optString("websiteDomain",request);
			if (websiteDomain!=null){
				merchantidisqc.setWebsiteDomain(websiteDomain);
			}
			String serviceNature=optString("serviceNature",request);
			if (serviceNature!=null){
				merchantidisqc.setServiceNature(serviceNature);
			}
			String certificate=optString("certificate",request);
			if (certificate!=null){
				merchantidisqc.setCertificate(certificate);
			}
			Date gmtValidity=optDate("gmtValidity", request, "yyyy-MM-dd HH:mm:ss");
			if (gmtValidity!=null) {
				merchantidisqc.setGmtValidity(gmtValidity);
			}
			merchantidisqc.setGmtModify(new Date());
			merchantidisqcService.saveOrUpdate(merchantidisqc);
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成");
		}		

		/**
		 * I-76
		 *查询互联网药品信息服务资格证书
		*/
		@ResponseBody
		@RequestMapping("sysUserGetInfo/getMerchantidisqcById")
		public String getMerchantidisqcById(ModelMap modelMap,HttpServletRequest request) throws BusinessException{
			Long id=getLong("id",request);
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			prams.put("merchantId", id);
			Merchantidisqc merchantidisqc=merchantidisqcService.getByParam(prams);
			if (merchantidisqc==null) {
				return JsonUtil.toJson(CommonInfoUtil.NULLDATA, "空数据");
			}
			return JsonUtil.toJson(CommonInfoUtil.SUCCESS, "操作完成",merchantidisqc);//jsonObject	json对象
		}

		
}
